package com.example.seh.add.idle;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import com.example.seh.R;
import com.example.seh.add.PubActivity;


import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TypeLabelActivity extends AppCompatActivity {

    @BindView(R.id.lgl_label)
    TypeLabelGridLayout lglLabel;
    @BindView(R.id.tv_reset)
    TextView tvReset;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;
    private List<FilterBean> typeLabelLists;


    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_type_label);
        ButterKnife.bind(this);
        initWindow();
        initData();
        setViewData();

    }
    protected void initWindow() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }
        getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
    }

    public static void show(Context context) {
        context.startActivity(new Intent(context, TypeLabelActivity.class));
    }

    private void initData() {
        //流式布局数据
        typeLabelLists = new ArrayList<>();
        List<FilterBean.TableMode> list = new ArrayList<>();
        list.add(new FilterBean.TableMode("其他"));
        list.add(new FilterBean.TableMode("电脑"));
        list.add(new FilterBean.TableMode("手机"));
        list.add(new FilterBean.TableMode("平板"));
        typeLabelLists.add(new FilterBean("电子产品", new FilterBean.TableMode("不限"), list));
        List<FilterBean.TableMode> list1 = new ArrayList<>();
        list1.add(new FilterBean.TableMode("其他"));
        list1.add(new FilterBean.TableMode("洗面奶"));
        list1.add(new FilterBean.TableMode("洗发水"));
        list1.add(new FilterBean.TableMode("沐浴露"));
        typeLabelLists.add(new FilterBean("生活用品", new FilterBean.TableMode("不限"), list1));
        List<FilterBean.TableMode> list2 = new ArrayList<>();
        list2.add(new FilterBean.TableMode("其他"));
        list2.add(new FilterBean.TableMode("帽子"));
        list2.add(new FilterBean.TableMode("短袖"));
        list2.add(new FilterBean.TableMode("外套"));
        typeLabelLists.add(new FilterBean("服饰", new FilterBean.TableMode("不限"), list2));
        List<FilterBean.TableMode> list3 = new ArrayList<>();
        list3.add(new FilterBean.TableMode("其他"));
        list3.add(new FilterBean.TableMode("全新"));
        list3.add(new FilterBean.TableMode("九成新"));
        list3.add(new FilterBean.TableMode("八成新"));
        typeLabelLists.add(new FilterBean("商品状态", new FilterBean.TableMode("不限"), list3));
        List<FilterBean.TableMode> list4 = new ArrayList<>();
        list4.add(new FilterBean.TableMode("不限"));
        list4.add(new FilterBean.TableMode("是"));
        list4.add(new FilterBean.TableMode("否"));
        typeLabelLists.add(new FilterBean("黑名单", new FilterBean.TableMode("不限"), list4));
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void setViewData() {

        lglLabel.setColumnCount(4);
        lglLabel.setLabelBg(R.drawable.flow_popup);
        lglLabel.setGridData(typeLabelLists);
    }

    @OnClick({R.id.tv_reset, R.id.tv_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_confirm:
                lglLabel.JudgeSelected();
                Log.e("rcw","label="+lglLabel.getLabelData());
                break;
            case R.id.tv_reset:
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        lglLabel.resetData();
                    }
                });

                break;
        }
    }
}
